#include "../comm.h"
class Foo {
private:
    mutex mtx;
    condition_variable cond1, cond2;
    bool f1, f2;
public:
    Foo() {
        f1 = f2 = false;
    }

    void first(function<void()> printFirst) {
        
        // printFirst() outputs "first". Do not change or remove this line.
        printFirst();
        f1 = true;
        cond1.notify_all();
    }

    void second(function<void()> printSecond) {
        unique_lock<mutex> lock(mtx);
        cond1.wait(lock, [this] { return this->f1; });
        // printSecond() outputs "second". Do not change or remove this line.
        printSecond();
        f2 = true;
        cond2.notify_all();
    }

    void third(function<void()> printThird) {
        unique_lock<mutex> lock(mtx);
        cond2.wait(lock, [this]{ return this->f2; });
        // printThird() outputs "third". Do not change or remove this line.
        printThird();
    }
};